import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

import java.lang.*;
import java.net.*;
import java.io.*;

/** The Action class is a simple example of a TCP/IP Socket Client.
 *
 */
public class Engine {

    int value;

    Engine(){
	value = 0;
    }

    public void changeState(Action action){

	String aid = action.getId();
	

	if(aid.equals(new String("add"))){
	    value += action.getValue();
	}
	
	if(aid.equals(new String("subtract"))){
	    value -= action.getValue();
	}

    }

    public int getValue(){
	return(value);
    }

    public String toString(){

	StringBuffer sb = new StringBuffer();
	sb.append(value);
	return sb.toString();
    }


    public Element toXmlElement(Document dom){

	/**
	 * Create root tag
	 */
	Element gameStateEle = dom.createElement("GameState");

	/**
	 * Fill with member tags
	 */
	Element valueEle = dom.createElement("GameStateValue");
	Text valueText = dom.createTextNode( (new Integer(getValue())).toString());
	valueEle.appendChild(valueText);
	gameStateEle.appendChild(valueEle);
	
	return gameStateEle;
	
    }



    
}